<#assign pageName="定时任务管理">
<@override name="page-content">
    <form class="layui-form form-horizontal" role="form" method="post">
        <div class="layui-form-search panel">
            <input type="text" hidden="hidden" name="_STATE"/>
            <@ctrl.SingleSelectQuery path="quartzJob.status" options={"NONE":"未启动", "N0RMAL":"运行中","PAUSED":"已暂停","COMPLETE":"已完成", "ERROR":"异常", "BLOCKED":"锁定"} text="1" value="0" labelText="任务状态">
                 <option value="">—全部—</option>
             </@ctrl.SingleSelectQuery>
            <@ctrl.TextboxQuery path="quartzJob.jobName" labelText="任务名称"/>
            <div class="margin-5">
                <a href="javascript:;" onclick="$('form:first').submit();" class="layui-btn layui-btn-sm">
                    <i class="layui-icon layui-icon-search"></i>查询
                </a>
                <a href="add" class="layui-btn layui-btn-normal layui-btn-sm">
                    <i class="layui-icon layui-icon-add-1"></i>新增
                </a>
                <#if isInStand?string('T', 'F') == 'F'>
                     <button type="button" class="layui-btn layui-btn-danger layui-btn-sm"
                        onclick="confirmSubmit('暂停定时器后，所有定时任务均被暂停？', {}, '../scheduler/stand')">
                        <i class="layui-icon layui-icon-pause"></i>定时器待机
                     </button>
                <#else>
                     <button type="button" class="layui-btn layui-btn-danger layui-btn-sm"
                        onclick="confirmSubmit('启动定时器后，所有定时任务即可正常触发？', {}, '../scheduler/start')">
                        <i class="layui-icon layui-icon-play"></i>定时器启动
                     </button>
                </#if>
            </div>
        </div>
        <table class="layui-table">
            <thead>
                <tr>
                    <th class="align-center" width="50px" nowrap="nowrap">序号</th>
                    <th class="align-center" nowrap="nowrap">任务名称</th>
                    <th class="align-center" nowrap="nowrap">cron表达式</th>
                    <th class="align-center" nowrap="nowrap">任务执行类</th>
                    <th class="align-center" width="120px">任务状态</th>
                    <th class="align-center" width="120px">任务分组</th>
                    <th class="align-center" width="150px">下次执行时间</th>
                    <th class="align-center" width="120px">操作</th>
                </tr>
            </thead>

            <tbody>
                <#if (queryResult.rows)?has_content>
                <#list (queryResult.rows) as dataItem>
                <tr>
                    <td class="align-center" width="50px" nowrap="nowrap">
                         ${(pageNo-1)*pageSize+dataItem_index+1}
                    </td>
                    <td nowrap="nowrap">
                        ${dataItem.jobName}
                    </td>
                    <td class="align-center" nowrap="nowrap">
                        ${dataItem.cronExpression}
                    </td>
                    <td nowrap="nowrap">
                        ${dataItem.beanClass}
                    </td>
                    <td class="align-center">
                        <#if dataItem.status == 'NONE'>未启动
                        <#elseif dataItem.status == 'NORMAL'>运行中
                        <#elseif dataItem.status == 'PAUSED'>已暂停
                        <#elseif dataItem.status == 'COMPLETE'>已完成
                        <#elseif dataItem.status == 'ERROR'>异常
                        <#elseif dataItem.status == 'BLOCKED'>锁定
                        </#if>
                    </td>
                    <td class="align-center" nowrap="nowrap">
                         <#if dataItem.jobGroup == '0'>默认
                        <#elseif dataItem.jobGroup == '1'>系统
                        </#if>
                    </td>
                    <td class="align-center" nowrap="nowrap">
                        <#if dataItem.nextExecDate?has_content>
                            ${dataItem.nextExecDate?datetime}
                        <#else>
                            —
                        </#if>
                    </td>
                    <td class="align-center">
                        <div class="layui-table-cell">
                             <a class="layui-btn layui-btn-warm layui-btn-xs" href="edit/${dataItem.id}">
                                <i class="layui-icon layui-icon-edit"></i>编辑
                             </a> 
                             <button type="button" class="layui-btn layui-btn-danger layui-btn-xs"
                                onclick="confirmSubmit('确定删除任务‘${dataItem.jobName}’数据？', {}, 'delete/${dataItem.id}')">
                                <i class="layui-icon layui-icon-delete"></i>删除
                             </button>
                             <button class="layui-btn layui-btn-primary layui-btn-xs more" data-id="${dataItem.id}">更多
                              <i class="layui-icon layui-icon-down"></i>
                            </button>
                        </div>
                    </td>
                </tr>
                </#list>
                <#else>
                    <tr>
                        <td colspan="9" style="color:red;text-align:center;font-weight:bold;">暂无符合条件的任务信息</td>
                    </tr>
                </#if>
            </tbody>
        </table>
    </form>
</@override>
<@override name="page-scripts">
    <script>
        $(function(){
            layui.use(['form','layer', 'jquery','dropdown'], function(){
                var form=layui.form;
                var layer=layui.layer;
                var $ = layui.jquery;
                var dropdown = layui.dropdown;
                dropdown.render({
                    elem: '.more' 
                    ,data: [{
                       title: '启动任务'
                       ,id: 'start'
                       ,href: '#'
                    },
                    {
                       title: '暂停任务'
                       ,id: 'pause'
                       ,href: '#'
                    },
                    {
                        title: '立即执行一次'
                        ,id: 'execute'
                        ,href: '#'
                    }]
                    ,click: function(obj){
                        var elem = $(this.elem)
                        ,jobId = elem.data('id');
                        submitData({}, obj.id + '/' + jobId);
                    }
                })
            })
        })
    </script>
</@override>
<@extends name="/layout/basepage.html"/> 